# arcflown.mod    
# by Yu Liu, 03/2001.   Based on survB.mod
# Arc-flow model for spare capacity allocation 
# considering all single NODE failures

set NODES;
set LINKS within {i1 in NODES, NODES diff {i1}};
set FLOWS := {i1 in NODES, NODES diff {i1}};
param M {FLOWS} integer default 1 >=0; 

param oR {NODES,LINKS} binary default 0;
param dR {NODES,LINKS} binary default 0;
param R {NODES,LINKS} integer default 0 >= -1 <= 1;
param oD {FLOWS,NODES} binary default 0;
param dD {FLOWS,NODES} binary default 0;
param D {FLOWS,NODES} integer default 0 >= -1 <= 1;

param A {FLOWS, LINKS} binary default 0;
param w {LINKS} integer default 0;

set FAILS;# := NODES;
param F {FAILS, LINKS} binary default 0;
param AF {FLOWS, FAILS} integer default 0;
param AFD {FLOWS, FAILS} binary default 0;
param AFDF {FLOWS, LINKS} integer default 0;

var B {FLOWS, LINKS} binary default 0;
var C {LINKS, FAILS} integer default 0;
var s {LINKS} integer default 0;

minimize w_cap:  sum {(i1,i2) in LINKS} w[i1,i2];
#s.t. mass_ba {(r1,r2) in FLOWS, n1 in NODES}:
#  sum {(i1,i2) in LINKS} A[r1,r2,i1,i2]*R[n1,i1,i2] 
#      = D[r1,r2,n1];
#s.t. cap_aggr {(i1,i2) in LINKS}:
#  w[i1,i2] = sum{(r1,r2) in FLOWS} A[r1,r2,i1,i2];
#problem find_work:  work_cost,  mass_ba, cap_aggr, A, w;

minimize s_cap: sum {(i1,i2) in LINKS} s[i1,i2];

s.t. mass_ba2 {(r1,r2) in FLOWS, n1 in NODES}:
  sum {(i1,i2) in LINKS} B[r1,r2,i1,i2]*R[n1,i1,i2]=D[r1,r2,n1];

s.t. cap_a2n {(i1,i2) in LINKS, f1 in FAILS diff {i1,i2}}:
  s[i1,i2] >= C[i1,i2,f1];

s.t. spm_node {(i1,i2) in LINKS, f1 in FAILS diff {i1,i2}}:
  C[i1,i2,f1] = sum{(r1,r2) in FLOWS} M[r1,r2] * 
     (B[r1,r2,i1,i2] * AFD[r1,r2,f1]);

s.t. node_disj {(r1,r2) in FLOWS,(i1,i2) in LINKS}:
  AFDF[r1,r2,i1,i2] + B[r1,r2,i1,i2] <= 1;

s.t. link_disj {(r1,r2) in FLOWS,(i1,i2) in LINKS}:
  A[r1,r2,i1,i2] + B[r1,r2,i1,i2] <=1;

problem sp_cap_node:
 s_cap,  mass_ba2, cap_a2n, 
  spm_node, node_disj, B, C, s;


param MaxNode integer default 5;
param MaxLink integer default 7;
param MaxFlow integer default 10;
param MaxHop integer default 6;

param t1 integer;
param t2 integer;
param ss integer;